﻿// MachineStatusView.cpp: 实现文件
//

#include "stdafx.h"
#include "DC-QC.h"
#include "MachineStatusView.h"


// CMachineStatusView

IMPLEMENT_DYNCREATE(CMachineStatusView, CFormView)

CMachineStatusView::CMachineStatusView()
	: CFormView(IDD_CMachineStatusView)
{
	m_nTick = 0;
	m_strOldMsg=_T("");
	m_nErrorLast=0;
	m_nSamplePreErrorLast=0;
	m_bUpdateFormView=FALSE;
}

CMachineStatusView::~CMachineStatusView()
{
}

void CMachineStatusView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_BTFSREFRESH, m_btFsRefresh);
}

BEGIN_MESSAGE_MAP(CMachineStatusView, CFormView)
	ON_WM_CREATE()
	ON_WM_SIZE()
	ON_WM_PAINT()
	ON_BN_CLICKED(IDC_BTFSREFRESH, &CMachineStatusView::OnBnClickedBtfsrefresh)
	ON_WM_TIMER()
END_MESSAGE_MAP()


// CMachineStatusView 诊断

#ifdef _DEBUG
void CMachineStatusView::AssertValid() const
{
	CFormView::AssertValid();
}

#ifndef _WIN32_WCE
void CMachineStatusView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}
#endif
#endif //_DEBUG


// CMachineStatusView 消息处理程序


BOOL CMachineStatusView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
	// TODO: 在此添加专用代码和/或调用基类

	return CFormView::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
}


int CMachineStatusView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CFormView::OnCreate(lpCreateStruct) == -1)
		return -1;

	// TODO:  在此添加您专用的创建代码
	CRect rect(0, 0, 10, 10);
	m_wndRTCurve.Create(NULL, NULL, WS_CHILD | WS_VISIBLE, rect, this, WND_MSCUVE_ID, NULL);

	return 0;
}

void CMachineStatusView::OnSize(UINT nType, int cx, int cy)
{
	CFormView::OnSize(nType, cx, cy);

	// TODO: 在此处添加消息处理程序代码
	CRect rect;
	GetClientRect(rect);
	try
	{
		if (m_wndRTCurve.m_hWnd && m_btFsRefresh.m_hWnd)
		{
			CRect rt = rect;
			rt.bottom = rect.Height() / 2;
			m_wndRTCurve.MoveWindow(rt);
			//一个刷新按钮
			CRect rtA = rect;
			rtA.right = rect.left + rect.Width() / 3-10*g_DPIScaleX;
			rtA.left = rtA.right - 80*g_DPIScaleX;
			rtA.top = rect.Height() / 2 + 10*g_DPIScaleY;
			rtA.bottom = rtA.top+35*g_DPIScaleY;
			m_btFsRefresh.MoveWindow(rtA);
			//两个编辑框
			rtA = rect;
			rtA.left = rect.left + rect.Width() / 3 + 10*g_DPIScaleX;
			rtA.right = rtA.left + rect.Width()*2 / 9-20*g_DPIScaleX;
			rtA.top = rect.Height() / 2 + 30*g_DPIScaleY;
			rtA.bottom = rect.bottom -10*g_DPIScaleY;
			CRect rtA1 = rtA;
			rtA1.bottom = rtA.top + rtA.Height() / 2 - 10*g_DPIScaleY;
			GetDlgItem(IDC_OUTBUF)->MoveWindow(rtA1);
			rtA1.top = rtA.top + rtA.Height() / 2 + 10*g_DPIScaleY;
			rtA1.bottom = rtA.bottom;
			GetDlgItem(IDC_INBUF)->MoveWindow(rtA1);
		}
	}
	catch (...)
	{
	}
}

void CMachineStatusView::OnInitialUpdate()
{
	CFormView::OnInitialUpdate();

	// TODO: 在此添加专用代码和/或调用基类
	m_btFsRefresh.SetIcon(IDI_REFRESH, NULL);
	m_strFS[0][0] = _T("软件安装目录");
	m_strFS[0][1] = _T("色谱图谱目录");
	m_strFS[0][2] = _T("当前数据库文件名");
	m_strFS[0][3] = _T("当前数据库大小");
	m_strFS[0][4] = _T("软件安装所在磁盘空间信息");
	m_strFS[0][5] = _T("图谱文件所在磁盘空间信息");

	//m_strPT[0] = _T("名称");
	//m_strPT[1] = _T("柱箱温度(℃)");
	//m_strPT[2] = _T("组份FID温度(℃)");
	//m_strPT[3] = _T("全烃FID温度(℃)");
	//m_strPT[4] = _T("组份A空气压力(kPa)");
	//m_strPT[5] = _T("组份A预切压力(kPa)");
	//m_strPT[6] = _T("组份A主柱压力(kPa)");
	//m_strPT[7] = _T("组份B空气压力(kPa)");
	//m_strPT[8] = _T("组份B预切压力(kPa)");
	//m_strPT[9] = _T("组份B主柱压力(kPa)");
	//m_strPT[10] = _T("全烃空气压力(kPa)");
	//m_strPT[11] = _T("全烃氢气压力(kPa)");
	//m_strPT[12] = _T("全烃样品气压力(kPa)");

		m_strPT[0] = _T("名称");
	m_strPT[1] = _T("柱箱温度(℃)");
	m_strPT[2] = _T("组份AFID温度(℃)");
	m_strPT[3] = _T("全烃FID温度(℃)");
	m_strPT[4] = _T("组份BFID温度(℃)");
	m_strPT[5] = _T("组份A空气压力(kPa)");
	m_strPT[6] = _T("组份A预切压力(kPa)");
	m_strPT[7] = _T("组份A主柱压力(kPa)");
	m_strPT[8] = _T("组份B空气压力(kPa)");
	m_strPT[9] = _T("组份B预切压力(kPa)");
	m_strPT[10] = _T("组份B主柱压力(kPa)");
	m_strPT[11] = _T("全烃空气压力(kPa)");
	m_strPT[12] = _T("全烃氢气压力(kPa)");
	m_strPT[13] = _T("全烃样品气压力(kPa)");
	OnBnClickedBtfsrefresh();
	m_nTimer = SetTimer(9004,2000, NULL);
}

//文件系统刷新
void CMachineStatusView::OnBnClickedBtfsrefresh()
{
	// TODO: 在此添加控件通知处理程序代码
	m_strFS[1][0] = m_strAppPath;
	m_strFS[1][1] = gl.gcCi.strFolder;
	CString strTemp;
	strTemp.Format(_T("%s.mdb"), gl.m_strWellName);
	m_strFS[1][2] = strTemp;
	strTemp.Format(_T("%s\\Wells\\%s.mdb"), m_strAppPath, gl.m_strWellName);
	float dSize=FileSize(strTemp);
	strTemp.Format(_T("%.1f Mb"), dSize);
	m_strFS[1][3] = strTemp;

	CString strPF = m_strAppPath.Left(2);
	ULARGE_INTEGER nFreeBytesAvailable, nTotalNumberOfBytes, nTotalNumberOfFreeBytes;
	long TotalSpace;	//磁盘空间MB 
	long FreeSpace;	//剩余空间MB 
	BOOL  ret = GetDiskFreeSpaceEx(strPF, &nFreeBytesAvailable, &nTotalNumberOfBytes, &nTotalNumberOfFreeBytes);
	if (ret == TRUE)
	{
		FreeSpace = nFreeBytesAvailable.QuadPart / 1048576;
		TotalSpace = nTotalNumberOfBytes.QuadPart / 1048576;
	}
	else
	{
		FreeSpace = 0;
		TotalSpace = 0;
	}
	strTemp.Format(_T("容量：%d Mb\n可用空间：%d Mb"), TotalSpace,FreeSpace);
	m_strFS[1][4] = strTemp;

	strPF = gl.gcCi.strFolder.Left(2);
	ret = GetDiskFreeSpaceEx(strPF, &nFreeBytesAvailable, &nTotalNumberOfBytes, &nTotalNumberOfFreeBytes);
	if (ret == TRUE)
	{
		FreeSpace = nFreeBytesAvailable.QuadPart / 1048576;
		TotalSpace = nTotalNumberOfBytes.QuadPart / 1048576;
	}
	else
	{
		FreeSpace = 0;
		TotalSpace = 0;
	}
	strTemp.Format(_T("容量：%d Mb\n可用空间：%d Mb"), TotalSpace, FreeSpace);
	m_strFS[1][5] = strTemp;
	Invalidate();
}

void CMachineStatusView::OnPaint()
{
	CPaintDC dc(this); // device context for painting
					   // TODO: 在此处添加消息处理程序代码
					   // 不为绘图消息调用 CFormView::OnPaint()
	CRect rect;
	GetClientRect(&rect);

	CBitmap ClientScreen, *pOldBitmap;
	CRect UpdateRect(rect);
	CDC MDC;
	MDC.CreateCompatibleDC(&dc);
	ClientScreen.CreateCompatibleBitmap(&dc, rect.Width(), rect.Height());
	pOldBitmap = MDC.SelectObject(&ClientScreen);
	MDC.FillSolidRect(UpdateRect, RGB(255, 255, 255));
	Draw(&MDC, rect);
	dc.BitBlt(UpdateRect.left, UpdateRect.top,
		UpdateRect.right - UpdateRect.left,
		UpdateRect.bottom - UpdateRect.top,
		&MDC, UpdateRect.left, UpdateRect.top, SRCCOPY);
	MDC.SelectObject(pOldBitmap);

	ClientScreen.DeleteObject();
	MDC.DeleteDC();
}

void	CMachineStatusView::Draw(CDC* pDC, CRect rt)
{
	try
	{
		DrawInBorder(pDC, rt);
		rt.DeflateRect(1, 1, 1, 1);
		BxGradientFill(pDC, rt, BACKCOLOR1, BACKCOLOR2, 1);
		CRect rtA = rt;
		rtA.top = rt.Height() / 2+2;
		rtA.right = rt.left+rt.Width() / 3;
		CFont* pF = (CFont*)pDC->SelectObject(&gl.m_pSmallFont); //保存当前字体
		pDC->SetBkMode(TRANSPARENT);
		DrawFileStatus(pDC, rtA);
		rtA.left = rtA.right;
		rtA.right = rt.left + rt.Width()*5 / 9;
		DrawWitsStatus(pDC, rtA);
		rtA.left = rtA.right;
		rtA.right = rt.left + rt.Width();
		DrawPTStatus(pDC, rtA);
		pDC->SelectObject(pF);		//恢复以前的字体
	}
	catch (...)
	{
	}
}

void	CMachineStatusView::DrawFileStatus(CDC* pDC, CRect rt)
{
	rt.DeflateRect(4, 4, 4, 4);
	BxGradientFill(pDC, rt, BACKCOLOR1, BACKCOLOR2, 1);

	CPen pPenA(PS_SOLID, 2, RGB(5, 85, 5));
	CPen* pOldPen = pDC->SelectObject(&pPenA);
	float  dCellH = rt.Height() /7.0;
	CRect rtCell = rt;
	rtCell.top = rt.top ;
	rtCell.bottom = rt.top +  dCellH;
	pDC->MoveTo(rtCell.TopLeft());
	pDC->LineTo(rtCell.right,rtCell.top);
	pDC->LineTo(rtCell.BottomRight());
	pDC->LineTo(rtCell.left, rtCell.bottom);
	pDC->LineTo(rtCell.TopLeft());
	pDC->SetTextColor(RGB(255, 255, 255));
	pDC->DrawTextW(_T("文件系统"), rtCell, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
	for (int i = 0; i < 6; i++)
	{
		rtCell.top = rt.top+(i+1)*dCellH;
		rtCell.bottom = rt.top + (i +2)*dCellH;
		pDC->MoveTo(rtCell.left, rtCell.bottom);
		pDC->LineTo(rtCell.BottomRight());
		CRect rtSCell = rtCell;
		rtSCell.right = rtCell.left + rtCell.Width() / 2;
		pDC->MoveTo(rtSCell.TopLeft());
		pDC->LineTo(rtSCell.left, rtSCell.bottom);
		pDC->MoveTo(rtSCell.right, rtSCell.top);
		pDC->LineTo(rtSCell.BottomRight());
		rtSCell.DeflateRect(2, 2, 2, 2);
		pDC->SetTextColor(RGB(0, 255, 205));
		pDC->DrawText(m_strFS[0][i], rtSCell, DT_LEFT | DT_VCENTER | DT_WORDBREAK | DT_EDITCONTROL);
		rtSCell = rtCell; 
		rtSCell.left = rtCell.left + rtCell.Width() / 2;
		pDC->MoveTo(rtSCell.right, rtSCell.top);
		pDC->LineTo(rtSCell.BottomRight());
		rtSCell.DeflateRect(2, 2, 2, 2);
		pDC->SetTextColor(RGB(255, 255, 20));
		pDC->DrawText(m_strFS[1][i], rtSCell, DT_LEFT | DT_VCENTER | DT_WORDBREAK | DT_EDITCONTROL);
	}
	pDC->SelectObject(pOldPen);
}

void	CMachineStatusView::DrawWitsStatus(CDC* pDC, CRect rt)
{
	rt.DeflateRect(2, 2, 2, 2);
	BxGradientFill(pDC, rt, BACKCOLOR1, BACKCOLOR2, 1);
	CRect rtCell = rt;
	pDC->SetTextColor(RGB(255, 255, 255));
	rtCell.top = rt.top + 5*g_DPIScaleY;
	rtCell.bottom = rtCell.top + 15*g_DPIScaleY;
	pDC->DrawTextW(_T("WITS输出数据流"), rtCell, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
	rtCell.top = rt.top + rt.Height() / 2 + 5*g_DPIScaleY;
	rtCell.bottom = rtCell.top + 15*g_DPIScaleY;
	pDC->DrawTextW(_T("WITS输入数据流"), rtCell, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
}

void	CMachineStatusView::DrawPTStatus(CDC* pDC, CRect rt)
{
	m_rtPT = rt;
	rt.DeflateRect(2, 2, 2, 2);
	BxGradientFill(pDC, rt, BACKCOLOR1, BACKCOLOR2, 1);

	CString strTemp;
	CPen pPenA(PS_SOLID, 2, RGB(5, 85, 5));
	CPen* pOldPen = pDC->SelectObject(&pPenA);
	pDC->MoveTo(rt.TopLeft());
	pDC->LineTo(rt.right, rt.top);
	pDC->LineTo(rt.BottomRight());
	pDC->LineTo(rt.left, rt.bottom);
	pDC->LineTo(rt.TopLeft());
	pDC->MoveTo(rt.left + rt.Width() / 3+20, rt.top);
	pDC->LineTo(rt.left + rt.Width() / 3+20, rt.bottom);
	int nRightPartLeft = rt.left + rt.Width() / 3 + 20;
	int nRightWidth = rt.Width() * 2 / 3 - 20;
	pDC->MoveTo(nRightPartLeft + nRightWidth / 3 , rt.top);
	pDC->LineTo(nRightPartLeft + nRightWidth / 3 , rt.bottom);
	pDC->MoveTo(nRightPartLeft + nRightWidth * 2 / 3 , rt.top);
	pDC->LineTo(nRightPartLeft + nRightWidth * 2 / 3 , rt.bottom);
	float  dCellH = rt.Height() / 14.0;
	CRect rtCell = rt;
	for (int i = 0; i < 14; i++)
	{
		rtCell.top = rt.top + i * dCellH;
		rtCell.bottom = rt.top + (i + 1)*dCellH;
		pDC->MoveTo(rtCell.left, rtCell.bottom);
		pDC->LineTo(rtCell.BottomRight());
		CRect rtSCell = rtCell;
		rtSCell.right = rtCell.left + rtCell.Width() / 3 + 20;
		rtSCell.DeflateRect(2, 2, 2, 2);
		if(i==0)
			pDC->SetTextColor(RGB(164, 255, 205));
		else if(i<5)
			pDC->SetTextColor(RGB(0xFF, 0x66, 0x00));
		else if (i < 8)
			pDC->SetTextColor(RGB(128, 255, 0));
		else if (i < 11)
			pDC->SetTextColor(RGB(0xFF, 0xFF, 0x00));
		else
			pDC->SetTextColor(RGB(0x80, 0x00, 0x80));

		pDC->DrawText(m_strPT[i], rtSCell, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
		rtSCell = rtCell;
		rtSCell.left = nRightPartLeft;
		rtSCell.right = nRightPartLeft + nRightWidth / 3;
		rtSCell.DeflateRect(2, 2, 2, 2);
		pDC->SetTextColor(RGB(255, 255, 255));
		if (i == 0)
			pDC->DrawText(_T("实际值"), rtSCell, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
		else
		{
			bool bChgLarge = FALSE;
			switch (i)
			{
			case 1:
				strTemp.Format(_T("%.1f"), gl.gcStatus.dColumTemp);
				if (fabs(gl.gcStatus.dColumTemp - gl.gcMachine.dColumTemp) > 4) bChgLarge = TRUE;
				break;
			case 2:
				strTemp.Format(_T("%.1f"), gl.gcStatus.dFid1Temp);
				if (fabs(gl.gcStatus.dFid1Temp - gl.gcMachine.dFid1Temp) > 4) bChgLarge = TRUE;
				break;
			case 3:
				strTemp.Format(_T("%.1f"), gl.gcStatus.dFid3Temp);
				if (fabs(gl.gcStatus.dFid3Temp - gl.gcMachine.dFid3Temp) > 4) bChgLarge = TRUE;
				break;
			case 4:
				strTemp.Format(_T("%.1f"), gl.gcStatus.dFid2Temp);
				if (fabs(gl.gcStatus.dFid2Temp - gl.gcMachine.dFid2Temp) > 4) bChgLarge = TRUE;
				break;
			case 5:
				strTemp.Format(_T("%.1f"), gl.gcStatus.m_dAAirP);
				if (fabs(gl.gcStatus.m_dAAirP - gl.gcMachine.dAAirPSet) > 4) bChgLarge = TRUE;
				break;
			case 6:
				strTemp.Format(_T("%.1f"), gl.gcStatus.m_dAH21P);
				if (fabs(gl.gcStatus.m_dAH21P - gl.gcMachine.dAH21PSet) > 4) bChgLarge = TRUE;
				break;
			case 7:
				strTemp.Format(_T("%.1f"), gl.gcStatus.m_dAH22P);
				if (fabs(gl.gcStatus.m_dAH22P - gl.gcMachine.dAH22PSet) > 4) bChgLarge = TRUE;
				break;
			case 8:
				strTemp.Format(_T("%.1f"), gl.gcStatus.m_dBAirP);
				if (fabs(gl.gcStatus.m_dBAirP - gl.gcMachine.dBAirPSet) > 4) bChgLarge = TRUE;
				break;
			case 9:
				strTemp.Format(_T("%.1f"), gl.gcStatus.m_dBH21P);
				if (fabs(gl.gcStatus.m_dBH21P - gl.gcMachine.dBH21PSet) > 4) bChgLarge = TRUE;
				break;
			case 10:
				strTemp.Format(_T("%.1f"), gl.gcStatus.m_dBH22P);
				if (fabs(gl.gcStatus.m_dBH22P - gl.gcMachine.dBH22PSet) > 4) bChgLarge = TRUE;
				break;
			case 11:
				strTemp.Format(_T("%.1f"), gl.gcStatus.m_dTGAirP);
				if (fabs(gl.gcStatus.m_dTGAirP - gl.gcMachine.dCAirPSet) > 4) bChgLarge = TRUE;
				break;
			case 12:
				strTemp.Format(_T("%.1f"), gl.gcStatus.m_dTGH2P);
				if (fabs(gl.gcStatus.m_dTGH2P - gl.gcMachine.dCH2PSet) > 4) bChgLarge = TRUE;
				break;
			case 13:
				strTemp.Format(_T("%.1f"), gl.gcStatus.m_dTGSampleP);
				if (fabs(gl.gcStatus.m_dTGSampleP - gl.gcMachine.dCSamplePSet) > 4) bChgLarge = TRUE;
				break;
			}
			if(bChgLarge)
				pDC->FillSolidRect(rtSCell,RGB(0,128,255));
			pDC->DrawText(strTemp, rtSCell, DT_CENTER | DT_VCENTER | DT_SINGLELINE);

		}
		rtSCell = rtCell;
		rtSCell.left = nRightPartLeft + nRightWidth / 3;
		rtSCell.right = rtSCell.left + nRightWidth / 3;
		pDC->SetTextColor(RGB(176, 255, 176));
		if (i == 0)
			pDC->DrawText(_T("设定值"), rtSCell, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
		else
		{
			switch (i)
			{
			case 1:
				strTemp.Format(_T("%.1f"), gl.gcMachine.dColumTemp);
				break;
			case 2:
				strTemp.Format(_T("%.1f"), gl.gcMachine.dFid1Temp);
				break;
			case 3:
				strTemp.Format(_T("%.1f"), gl.gcMachine.dFid3Temp);
				break;
			case 4:
				strTemp.Format(_T("%.1f"), gl.gcMachine.dFid2Temp);
				break;
			case 5:
				strTemp.Format(_T("%.1f"), gl.gcMachine.dAAirPSet);
				break;
			case 6:
				strTemp.Format(_T("%.1f"), gl.gcMachine.dAH21PSet);
				break;
			case 7:
				strTemp.Format(_T("%.1f"), gl.gcMachine.dAH22PSet);
				break;
			case 8:
				strTemp.Format(_T("%.1f"), gl.gcMachine.dBAirPSet);
				break;
			case 9:
				strTemp.Format(_T("%.1f"), gl.gcMachine.dBH21PSet);
				break;
			case 10:
				strTemp.Format(_T("%.1f"), gl.gcMachine.dBH22PSet);
				break;
			case 11:
				strTemp.Format(_T("%.1f"), gl.gcMachine.dCAirPSet);
				break;
			case 12:
				strTemp.Format(_T("%.1f"), gl.gcMachine.dCH2PSet);
				break;
			case 13:
				strTemp.Format(_T("%.1f"), gl.gcMachine.dCSamplePSet);
				break;
			}
			pDC->DrawText(strTemp, rtSCell, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
		}

		rtSCell = rtCell;
		rtSCell.left = nRightPartLeft + nRightWidth * 2 / 3;
		rtSCell.right = rtSCell.left + nRightWidth / 3;
		pDC->SetTextColor(RGB(255, 155, 155));
		if (i == 0)
			pDC->DrawText(_T("流量(ml/min)"), rtSCell, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
		else
		{
			switch (i)
			{
			case 1:
				strTemp=_T("");
				break;
			case 2:
				strTemp = _T("");
				break;
			case 3:
				strTemp = _T("");
				break;			
			case 4:
				strTemp = _T("");
				break;
			case 5:
				strTemp.Format(_T("%.1f"), gl.gcMachine.sFlow[0].dValue);
				break;
			case 6:
				strTemp.Format(_T("%.1f"), gl.gcMachine.sFlow[1].dValue);
				break;
			case 7:
				strTemp.Format(_T("%.1f"), gl.gcMachine.sFlow[2].dValue);
				break;
			case 8:
				strTemp.Format(_T("%.1f"), gl.gcMachine.sFlow[3].dValue);
				break;
			case 9:
				strTemp.Format(_T("%.1f"), gl.gcMachine.sFlow[4].dValue);
				break;
			case 10:
				strTemp.Format(_T("%.1f"), gl.gcMachine.sFlow[5].dValue);
				break;
			case 11:
				strTemp.Format(_T("%.1f"), gl.gcMachine.sFlow[6].dValue);
				break;
			case 12:
				strTemp.Format(_T("%.1f"), gl.gcMachine.sFlow[7].dValue);
				break;
			case 13:
				strTemp.Format(_T("%.1f"), gl.gcMachine.sFlow[8].dValue);
				break;
			}
			pDC->DrawText(strTemp, rtSCell, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
			pDC->SetTextColor(RGB(176, 255, 176));
		}
		pDC->SelectObject(pOldPen);
	}
}

void CMachineStatusView::OnTimer(UINT_PTR nIDEvent)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	if (m_nTimer == nIDEvent)
	{
		if(!m_bUpdateFormView)
		{
			CRect rect;
			GetClientRect(&rect);
			PostMessage(WM_SIZE, (WPARAM)SIZE_RESTORED, MAKELPARAM(rect.Width(), rect.Height()));
			m_bUpdateFormView=TRUE;
		}
		GetDlgItem(IDC_OUTBUF)->SetWindowTextW(gl.ChromWits.strWitsOutBuf);
		GetDlgItem(IDC_INBUF)->SetWindowTextW(gl.ChromWits.strWitsInBuf);
		InvalidateRect(m_rtPT, FALSE);

		m_nTick++;
		if (m_nTick % 30 == 0)
		{
			gl.m_strNewMsg2=_T("");
			for (int i = 1; i < 13; i++)
			{
				CString strTemp = _T("");
				switch (i)
				{
				case 1:
					if (fabs(gl.gcStatus.dColumTemp - gl.gcMachine.dColumTemp) > 5) strTemp = _T("柱温异常，请注意！");
					break;
				case 2:
					if (fabs(gl.gcStatus.dFid1Temp - gl.gcMachine.dFid1Temp) > 2) strTemp = _T("组份鉴定器温度异常，请注意！");
					break;
				case 3:
					if (fabs(gl.gcStatus.dFid3Temp - gl.gcMachine.dFid3Temp) > 2) strTemp = _T("全烃鉴定器温度异常，请注意！");
					break;
				case 4:
					if (fabs(gl.gcStatus.m_dAAirP - gl.gcMachine.dAAirPSet) > 4 && gl.m_nWorkMode!=2) strTemp = _T("组份A通道空气压力异常，请注意！");
					break;
				case 5:
					if (fabs(gl.gcStatus.m_dAH21P - gl.gcMachine.dAH21PSet) > 4  && gl.m_nWorkMode!=2) strTemp = _T("组份A通道预切氢气压力异常，请注意！");
					break;
				case 6:
					if (fabs(gl.gcStatus.m_dAH22P - gl.gcMachine.dAH22PSet) > 4 && gl.m_nWorkMode!=2 ) strTemp = _T("组份A通道主柱氢气压力异常，请注意！");
					break;
				case 7:
					if (fabs(gl.gcStatus.m_dBAirP - gl.gcMachine.dBAirPSet) > 1  && gl.m_nWorkMode!=1) strTemp = _T("组份B通道空气压力异常，请注意！");
					break;
				case 8:
					if (fabs(gl.gcStatus.m_dBH21P - gl.gcMachine.dBH21PSet) > 4  && gl.m_nWorkMode!=1) strTemp = _T("组份B通道预切氢气压力异常，请注意！");
					break;
				case 9:
					if (fabs(gl.gcStatus.m_dBH22P - gl.gcMachine.dBH22PSet) > 4  && gl.m_nWorkMode!=1) strTemp = _T("组份B通道主柱氢气压力异常，请注意！");
					break;
				case 10:
					if (fabs(gl.gcStatus.m_dTGAirP - gl.gcMachine.dCAirPSet) > 4) strTemp = _T("全烃鉴定器空气压力异常，请注意！");
					break;
				case 11:
					if (fabs(gl.gcStatus.m_dTGH2P - gl.gcMachine.dCH2PSet) > 4) strTemp = _T("全烃鉴定器氢气压力异常，请注意！");
					break;
				case 12:
					if (fabs(gl.gcStatus.m_dTGSampleP - gl.gcMachine.dCSamplePSet) > 4) strTemp = _T("样品气压力异常，请注意！");
					break;
				}
				gl.m_strNewMsg2 = gl.m_strNewMsg2 + strTemp;
			}
			gl.m_strNewMsg2.Trim();
			//错误延续时间，超过12秒时，还有错误，则再次进行播报。若12秒正常了，正回原始状态
			if(gl.m_strNewMsg2 != _T("")) 
				m_nErrorLast=m_nErrorLast+6;
			else
			{
				m_strOldMsg=_T("");
				m_nErrorLast=0;
			}
			if(m_nErrorLast>30)
			{
				m_strOldMsg=_T("");
				m_nErrorLast=0;
			}

			if (gl.m_strNewMsg2.GetLength()!=0 && gl.m_strNewMsg2 != m_strOldMsg)
			{
				m_strOldMsg=gl.m_strNewMsg2;
				AfxBeginThread(Speech_Info2, NULL, THREAD_PRIORITY_NORMAL);
			}
			if (gl.m_strNewMsg2.GetLength()==0) m_strOldMsg=gl.m_strNewMsg2;

			//监测样品气压力是否由0->正常值
			if (fabs(gl.gcStatus.m_dTGSampleP - gl.gcMachine.dCSamplePSet) > 4 && gl.m_bRun && fabs(gl.gcStatus.m_dTGH2P - gl.gcMachine.dCH2PSet) > 4 && fabs(gl.gcStatus.m_dTGAirP - gl.gcMachine.dCAirPSet) > 4) m_nSamplePreErrorLast++;
			else m_nSamplePreErrorLast=0;
			if(m_nSamplePreErrorLast>=4)
			{
				cControl.SetEPCPars();
				m_nSamplePreErrorLast=0;
			}
		}
	}
	CFormView::OnTimer(nIDEvent);
}
